let init = {
    nameSpace: "mall",
    saveItem(key, value) {
        console.log(key,value)
        let storage = window.localStorage.getItem(this.nameSpace)
        if (!storage){
            storage = {}
        }else{
            storage = JSON.parse(storage)
        }
        storage[key] = value
        window.localStorage.setItem(this.nameSpace,JSON.stringify(storage))
    },
    loadItem(key,def){
        //def 默认值
        let storage = window.localStorage.getItem(this.nameSpace)
        if(!storage){
            return def
        }

        storage = JSON.parse(storage)
        let result = storage[key]
        return result || def
    }
}
export {init}